
<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col
            :md="5"
            :sm="15"
          >
            <a-form-item label="报表生成时间">
              <a-date-picker
                v-model="queryParam.reportGenerationTime"
                placeholder="报表生成时间"
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="5"
            :sm="15"
          >
            <a-form-item label="批次号">
              <a-input
                placeholder="请输入"
                v-model="queryParam.batchNo"
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="5"
            :sm="15"
          >
            <a-form-item label="保费总额">
              <a-input
                placeholder="请输入"
                v-model="queryParam.totalInsurancePremium"
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="5"
            :sm="15"
          >
            <a-form-item label="保单号">
              <a-input
                placeholder="请输入"
                v-model="queryParam.lossPolicy"
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="4"
            :sm="24"
          >
            <span class="table-page-search-submitButtons">
              <a-button
                type="primary"
                @click="$refs.table.refresh(true)"
              >查询</a-button>
              <a-button
                style="margin-left: 8px"
                @click="() => queryParam = {}"
              >重置</a-button>
              <span
                class="iconStyle"
                @click="() => upDownFlag = !upDownFlag"
              >
                <a-icon :type="upDownFlag?'up':'down'" />
              </span>

            </span>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col
            :md="5"
            :sm="15"
            v-show="upDownFlag"
          >
            <a-form-item label="保单生效时间">
              <a-date-picker
                v-model="queryParam.reportGenerationTime"
                placeholder="报表生成时间"
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="5"
            :sm="15"
            v-show="upDownFlag"
          >
            <a-form-item label="支付状态">
              <a-select
                v-model="queryParam.payStatus"
                placeholder="请选择支付状态"
              >
                <a-select-option value="">全部</a-select-option>
                <a-select-option value="3">未支付</a-select-option>
                <a-select-option value="4">已支付</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col
            :md="5"
            :sm="15"
            v-show="upDownFlag"
          >
            <a-form-item label="支付时间">
              <a-date-picker
                v-model="queryParam.payTime"
                placeholder="支付时间"
              />
            </a-form-item>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <s-table
      size="default"
      ref="table"
      rowKey="roleId"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      :columns="columns"
      :data="loadData"
      defaultSort="createTime"
      :scroll="{x:1180}"
    >
      <span
        slot="id"
        slot-scope="text,record,index"
      >
        {{ index + 1 }}
      </span>
    </s-table>
    <div class="footer">
      <div class="content">
        <span
          v-show="selectedRowKeys.length===0"
          class="placeHoldStyle"
        >
          注：请选择条目后操作
        </span>
        <span class="title">支付状态：</span>
        <span class="buttonBox">
          <a-button
            type="primary"
            @click="HavePay"
            class="HavePayButton"
            :disabled="selectedRowKeys.length===0"
          >已支付</a-button>
          <a-button
            style="margin-left: 20px;margin-right: 50px"
            type="primary"
            @click="noPay"
            :disabled="selectedRowKeys.length===0"
          >未支付</a-button>
        </span>
        <span class="payTime">
          <a-date-picker
            v-model="payTime"
            :disabled="selectedRowKeys.length===0"
          />
          <a-button
            style="margin-left: 20px;margin-right: 50px"
            type="primary"
            @click="addPayTime"
            :disabled="selectedRowKeys.length===0"
          >添加支付时间</a-button>
        </span>
      </div>
    </div>
  </a-card>
</template>

<script>
// 界面是支付管理界面
import { STable } from '@/components'
import { sysInsuranceDetailspayList, delRole, changRoleStatus, updatePayStatusAndPayTime } from '@/api/system'
import RoleModal from '../modules/RoleModal.vue'
import RoleScopeModal from '../modules/RoleScopeModal.vue'
import pick from 'lodash.pick'
import moment from 'moment'
export default {
  name: 'SysInsuranceDetailsList',
  components: {
    STable,
    RoleModal,
    RoleScopeModal
  },
  data () {
    return {
      description: '列表使用场景：后台管理中的权限管理以及角色管理，可用于基于 RBAC 设计的角色权限控制，颗粒度细到每一个操作类型。',
      visible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      form: this.$form.createForm(this),
      mdl: {},
      permissions: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      payTime: '',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'Id',
          width: 80,
          scopedSlots: { customRender: 'id' }
        },
        {
          title: '报表生成时间',

          width: 200,
          dataIndex: 'reportGenerationTime'
        },
        {
          title: '批次号',
          width: 100,
          dataIndex: 'batchNo'
        },
        {
          title: '订单数量',
          width: 100,
          dataIndex: 'orderNum'
        },
        {
          title: '保费总金额',
          width: 100,
          dataIndex: 'totalInsurancePremium',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '保单号',
          width: 100,
          dataIndex: 'lossPolicy'
        },
        {
          title: '保单生效时间',
          width: 200,
          dataIndex: 'insuranceStartdate'
        },
        {
          title: '支付状态',
          width: 100,
          dataIndex: 'payStatus',
          customRender: (text) => text === 4 || text === '4' ? '已支付' : '未支付'
          //   sorter: true
        },
        {
          title: '支付时间',
          width: 200,
          dataIndex: 'payTime'
          //   sorter: true
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return sysInsuranceDetailspayList(Object.assign(parameter, this.queryParam))
      },
      selectedRowKeys: [],
      selectedRows: [],
      upDownFlag: false
    }
  },
  created () {
  },
  methods: {
    onSelectChange (selectedRowKeys) {
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      this.selectedRowKeys = selectedRowKeys
    },
    handleAdd (parentId) {
      this.$refs.modal.add(parentId)
    },
    handleEdit (record) {
      this.$refs.modal.edit(record)
    },
    handleScope (record) {
      this.$refs.scopemodal.edit(record)
    },
    onChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    handleOk () {
      this.$refs.table.refresh(true)
      console.log('handleSaveOk')
    },
    delByIds (ids) {
      delRole({ ids: ids.join(',') }).then(res => {
        if (res.code === 0) {
          this.$message.success(`删除成功`)
          this.handleOk()
        } else {
          this.$message.error(res.msg)
        }
        // const difference = new Set(this.selectedRowKeys.filter(x => !new Set(ids).has(x)))
        // this.selectedRowKeys = Array.from(difference)
        this.selectedRowKeys = []
      })
    },
    onChangeStatus (record) {
      record.status = record.status === '0' ? '1' : '0'
      changRoleStatus(pick(record, 'roleId', 'status'))
      // 发送状态到服务器
    },
    HavePay () {
      console.log('我点击了已支付')
      const parmas = this.selectedRowKeys.map(item => (
        {
          id: item,
          payStatus: '4',
          payTime: ''
        }
      ))
      updatePayStatusAndPayTime(parmas).then(res => {
        if (res.code === 0) {
          this.$message.success('修改成功')
          this.handleOk()
        } else {
          this.$message.error(res.msg)
        }
      })
    },

    noPay () {
      console.log('我点击了未支付')
      const parmas = this.selectedRowKeys.map(item => (
        {
          id: item,
          payStatus: '3',
          payTime: ''
        }
      ))
      updatePayStatusAndPayTime(parmas).then(res => {
        if (res.code === 0) {
          this.$message.success('修改成功')
          this.handleOk()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    addPayTime () {
      if (!this.payTime) {
        this.$$message.error('请先选择时间在进行操作')
        return false
      }
      const parmas = this.selectedRowKeys.map(item => (
        {
          id: item,
          payStatus: '',
          payTime: moment(this.payTime).format('YYYY-MM-DD')
        }
      ))
      updatePayStatusAndPayTime(parmas).then(res => {
        if (res.code === 0) {
          this.$message.success('修改成功')
          this.handleOk()
        } else {
          this.$message.error(res.msg)
        }
      })
    }
  }
}
</script>
<style lang='less' scoped>
.footer {
  width: 100%;
}
.footer .content {
  width: auto;
  text-align: center;
  box-sizing: border-box;
  padding-top: 70px;
}
.footer .content .placeHoldStyle {
  display: inline-block;
  font-size: 14px;
  color: #999999;
  margin-right: 40px;
}
.footer .content .title {
  display: inline-block;
  font-size: 14px;
  color: #333333;
  margin-right: 16px;
}
.iconStyle {
  padding-left: 10px;
}
</style>
